package com.itwlj.controller.admin;

import com.itwlj.entity.Banner;
import com.itwlj.result.Result;
import com.itwlj.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图管理
 */
@RestController
@RequestMapping("admin/banner")
@Api(tags = "轮播图相关接口")
@Slf4j
public class BannerController {

    @Autowired
    private BannerService bannerService;

    /**
     * 新增轮播图
     *
     * @param banner
     * @return
     */
    @PostMapping
    @ApiOperation("新增轮播图")
    public Result<String> insert(@RequestBody Banner banner) {
        log.info("新增轮播图：{}", banner);
        bannerService.insert(banner);
        return Result.success();
    }

    /**
     * 查询轮播图
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询轮播图")
    public Result<List<Banner>> list() {
        log.info("查询轮播图");
        List<Banner> bannerList = bannerService.list();
        return Result.success(bannerList);
    }

    /**
     * 删除轮播图
     *
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除轮播图")
    public Result<String> deleteById(Long id) {
        log.info("删除轮播图：{}", id);
        bannerService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改轮播图
     *
     * @param banner
     * @return
     */
    @PutMapping
    @ApiOperation("修改轮播图")
    public Result<String> update(@RequestBody Banner banner) {
        log.info("修改轮播图：{}", banner);
        bannerService.update(banner);
        return Result.success();
    }
}
